#!/usr/bin/env python
# Create: 2018/10/24
# __author__ = '749B'
"""socket HTTP/1.0"""

import socket
from bs4 import BeautifulSoup

client = socket.socket()
# 连接
client.connect(('edu.51cto.com', 80))
# 发送
header = b'GET / HTTP/1.0\r\nHost: edu.51cto.com\r\n\r\n'
client.sendall(header)
# 接收
data = client.recv(1024)
content = b''
while data:
    content += data
    data = client.recv(1024)
head, body = content.split(b'\r\n\r\n')
print(head)
print(len(body), body)
soup = BeautifulSoup(body.decode(), features='html.parser')
title = soup.find('title')
print(title)
